<?php

class InvoiceLineController extends ExtCRUDController
{
    protected function handleReadAction()
    {
        if (isset($_POST['id']))
        {
            $total = 1;
            $data = Invoiceline::model()->findAll('InvoiceId = :cid', array(':cid' => $_POST['id']));
            $result = array();

            /**
             * This is a hack for not creating a MySQL view
             */
            foreach($data as $key => $line)
            {
                // make a simple array from the InvoiceLine object
                $line = CJSON::decode(CJSON::encode($line));
                $track = Track::model()->find('TrackId=:id',array(':id'=>$line['TrackId']));
                $line['TrackId'] = $track->Name;
                $result[]=$line;
            }
            $data = $result;
        }
        else
        {
            $total = 0;
            $data = array();
        }
        return $this->ExportToJSONDataSource($data, $total);
    }

    protected function handleCreateAction($rows)
    {
        return false;
    }

    protected function handleDestroyAction($id)
    {
        return false;
    }

    protected function handleUpdateAction($rows)
    {
        return true;
    }

}

?>
